package com.study.zjh.smartrefreshdemo.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.billy.android.swipe.SmartSwipe;
import com.billy.android.swipe.SmartSwipeWrapper;
import com.billy.android.swipe.SwipeConsumer;
import com.billy.android.swipe.SwipeConsumerExclusiveGroup;
import com.billy.android.swipe.consumer.DrawerConsumer;
import com.billy.android.swipe.consumer.SlidingConsumer;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.study.zjh.smartrefreshdemo.R;
import com.study.zjh.smartrefreshdemo.base.BaseActivity;

public class ScrollViewActivity extends BaseActivity {

    private RefreshLayout refreshLayout;
    private RelativeLayout rl_top;
    private RelativeLayout rl_top2;
    private SwipeConsumerExclusiveGroup exclusiveGroup = new SwipeConsumerExclusiveGroup();
    private SwipeConsumerExclusiveGroup exclusiveGroup2 = new SwipeConsumerExclusiveGroup();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_view);
        refreshLayout=(RefreshLayout)findViewById(R.id.srl);
        rl_top=(RelativeLayout)findViewById(R.id.rl_top);
        rl_top2=(RelativeLayout)findViewById(R.id.rl_top2);
        initSmartRefresh();
        refreshLayout.setEnableLoadMore(false);

        SmartSwipeWrapper wrapper = findViewById(R.id.main_ui_wrap_view);
        wrapper.addConsumer(new SlidingConsumer()).setRelativeMoveFactor(SlidingConsumer.FACTOR_FOLLOW).addToExclusiveGroup(exclusiveGroup2);
        Button button = (Button) findViewById(R.id.star_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ScrollViewActivity.this,"点击Button",Toast.LENGTH_SHORT).show();
                exclusiveGroup2.markNoCurrent();
            }
        });



        TextView textView = new TextView(ScrollViewActivity.this);
        textView.setBackgroundColor(0xFFAA0000);
        textView.setTextColor(0xFFFFFFFF);
        textView.setTextSize(14);
        textView.setText("编编辑编辑编辑编辑辑");
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT));
        final SwipeConsumer consumer = SmartSwipe.wrap(rl_top)
                .addConsumer(new DrawerConsumer())
                .setHorizontalDrawerView(textView)
                .setScrimColor(0x2F000000)
                .setShadowColor(0x80000000)
                .addToExclusiveGroup(exclusiveGroup);
//                .setInterpolator(new OvershootInterpolator());
//        SmartSwipe.wrap(rl_top)
//                .addConsumer(consumer)
//                .enableHorizontal()                 //仿iOS弹性留白效果的方向为：左右2个方向
        ;
        TextView textView2 = new TextView(ScrollViewActivity.this);
        textView2.setBackgroundColor(0xFFAA0000);
        textView2.setTextColor(0xFFFFFFFF);
        textView2.setTextSize(14);
        textView2.setText("编编辑编辑编辑编辑辑");
        textView2.setGravity(Gravity.CENTER);
        textView2.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT));
        rl_top2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                exclusiveGroup.markNoCurrent();
            }
        });

        final SwipeConsumer consumer2 = SmartSwipe.wrap(rl_top2)
                .addConsumer(new DrawerConsumer())
                .setHorizontalDrawerView(textView2)
                .setScrimColor(0x2F000000)
                .setShadowColor(0x80000000)
                .addToExclusiveGroup(exclusiveGroup);
//                .setInterpolator(new OvershootInterpolator());
        ;
//        SmartSwipe.wrap(rl_top2)
//                .addConsumer(consumer2)
//                .enableHorizontal()                 //仿iOS弹性留白效果的方向为：左右2个方向
        ;
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                exclusiveGroup.markNoCurrent();
                Toast.makeText(ScrollViewActivity.this,"点击",Toast.LENGTH_SHORT).show();
//                SmartSwipe.peekWrapperFor(consumer.getWrapper());
                Intent intent = new Intent(ScrollViewActivity.this,SmartSwipeListActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initSmartRefresh() {
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshLayout.finishRefresh(2000/*,false*/);
                //不传时间则立即停止刷新    传入false表示刷新失败
            }
        });
    }
}
